package com.burstly.lib.component.networkcomponent.burstly.html.rewards;

import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.widget.VideoView;
import com.burstly.lib.component.networkcomponent.burstly.NoSeekMediaController;
import com.burstly.lib.component.networkcomponent.burstly.html.VideoViewPane;
import com.burstly.lib.component.networkcomponent.burstly.video.VideoCache;
import com.burstly.lib.util.Utils;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

final class RewardsVideoView extends VideoViewPane
  implements Runnable, MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener, ThreadFactory
{
  private ScheduledExecutorService mExecutor = Executors.newSingleThreadScheduledExecutor(this);
  private MediaPlayer.OnCompletionListener mOnCompletionListener;
  private MediaPlayer.OnErrorListener mOnErrorListener;
  private MediaPlayer.OnPreparedListener mOnPrepListener;
  private String mOriginalVideoUrl;
  private volatile boolean mPrepared;
  private RewardsMediaController mRewardsMediaController;
  private volatile IVideoEvents mVideoEventsListener;

  RewardsVideoView(Context paramContext)
  {
    super(paramContext);
    super.setListeners(this, this, this);
  }

  public void destroy()
  {
    super.destroy();
    getVideoView().setMediaController(null);
    this.mExecutor.shutdownNow();
    this.mExecutor = null;
    this.mOnPrepListener = null;
    this.mOnCompletionListener = null;
    this.mOnErrorListener = null;
  }

  protected NoSeekMediaController getMediaController()
  {
    if (this.mRewardsMediaController == null)
      this.mRewardsMediaController = new RewardsMediaController(getContext());
    return this.mRewardsMediaController;
  }

  String getOriginalVideoUrl()
  {
    return this.mOriginalVideoUrl;
  }

  IVideoEvents getVideoEventsListener()
  {
    return this.mVideoEventsListener;
  }

  boolean isPaused()
  {
    return this.mRewardsMediaController.isPaused();
  }

  boolean isPrepared()
  {
    return this.mPrepared;
  }

  public Thread newThread(Runnable paramRunnable)
  {
    return new Thread(paramRunnable);
  }

  public void onCompletion(MediaPlayer paramMediaPlayer)
  {
    if (this.mOnCompletionListener != null)
      this.mOnCompletionListener.onCompletion(paramMediaPlayer);
    if (this.mVideoEventsListener != null)
      this.mVideoEventsListener.ended();
  }

  public boolean onError(MediaPlayer paramMediaPlayer, int paramInt1, int paramInt2)
  {
    if (this.mVideoEventsListener != null)
      this.mVideoEventsListener.error();
    if (this.mOnErrorListener != null)
      return this.mOnErrorListener.onError(paramMediaPlayer, paramInt1, paramInt2);
    return false;
  }

  public void onPrepared(MediaPlayer paramMediaPlayer)
  {
    this.mPrepared = true;
    if (this.mVideoEventsListener != null)
      this.mVideoEventsListener.started();
    this.mExecutor.scheduleAtFixedRate(this, 0L, 1L, TimeUnit.SECONDS);
    if (this.mOnPrepListener != null)
      this.mOnPrepListener.onPrepared(paramMediaPlayer);
  }

  public void playVideo(String paramString)
  {
    String str = VideoCache.getInstance(getContext()).hasFileInCache(paramString);
    this.mOriginalVideoUrl = paramString;
    this.mPrepared = false;
    if (str != null);
    while (true)
    {
      super.playVideo(str);
      return;
      str = paramString;
    }
  }

  public void run()
  {
    Utils.lowerCurrentThreadPriority();
    VideoView localVideoView = getVideoView();
    if ((this.mVideoEventsListener != null) && (localVideoView != null) && (localVideoView.isPlaying()))
      this.mVideoEventsListener.timeUpdate(localVideoView.getCurrentPosition());
  }

  public void setListeners(MediaPlayer.OnPreparedListener paramOnPreparedListener, MediaPlayer.OnCompletionListener paramOnCompletionListener, MediaPlayer.OnErrorListener paramOnErrorListener)
  {
    this.mOnPrepListener = paramOnPreparedListener;
    this.mOnCompletionListener = paramOnCompletionListener;
    this.mOnErrorListener = paramOnErrorListener;
  }

  void setVideoEventsListener(IVideoEvents paramIVideoEvents)
  {
    this.mVideoEventsListener = paramIVideoEvents;
    this.mRewardsMediaController = ((RewardsMediaController)getMediaController());
    this.mRewardsMediaController.setVideoListener(paramIVideoEvents);
  }

  static abstract interface IVideoEvents
  {
    public abstract void ended();

    public abstract void error();

    public abstract void paused();

    public abstract void started();

    public abstract void timeUpdate(int paramInt);

    public abstract void unpaused();
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.rewards.RewardsVideoView
 * JD-Core Version:    0.6.2
 */